        pair<db,db> res1=calc(mxh,mxr,mxR,mxH);
        pair<db,db> res2=calc(lsh,lsr,lsR,lsH);
        pair<db,db> res3=calc(h,r,R,h);
        db ma=res1.first,mb=res1.second;
        db la=res2.first,lb=res2.second;
        db a=res3.first,b=res3.second;
        int flg=0;
        if(lsH-lsh<=Connet(la,lb,r) && Connet(la,lb,r)<=lsH) flg=3;
        if(lsH-lsh<=Connet(la,lb,R)-h && Connet(la,lb,R)<=lsH) flg=4;
        if(lsr>=r && lsR<=R && check(lsR,lsH,lsh,a,b)) flg=5;
        if(mxH-mxh<=Connet(ma,mb,r) && Connet(ma,mb,r)<=mxH) flg=1;
        if(mxH-mxh<=Connet(ma,mb,R)-h && Connet(ma,mb,R)<=mxH) flg=2;
        if(mxr>=r && mxR<=R && check(mxR,mxH,mxh,a,b)) flg=6;
        if(!flg) {
            if(h+ans>=mxH) {
                Init(3,h,r,R,ans+h);
            } else {
                mxh=(mxH-ans-h);
                Init(2,h,r,R,ans+h);
            }
        }
        if(flg==6) {
            b=mxH-a*mxR;
            db ph=a*r+b;
            ans+=ph-ans;
            if(ans+h>=mxH) {
                Init(3,h,r,R,ans+h);
            } else {
                mxh=(mxH-ans-h);
                Init(2,h,r,R,ans+h);
            }
        }
        if(flg==5) {
            b=lsH-a*lsR;
            db ph=a*r+b;
            ans+=ph-ans;
            if(ans+h>=mxH) {
                Init(3,h,r,R,ans+h);
            } else {
                mxh=(mxH-ans-h);
                Init(2,h,r,R,ans+h);
            }
        }
        if(flg==1) {
            ans+=Connet(ma,mb,r)-ans;
            if(h+ans>=mxh) {
                Init(3,h,r,R,ans+h);
            } else {
                mxh=(mxH-ans-h);
                Init(2,h,r,R,ans+h);
            }
        }
        if(flg==2) {
            ans+=Connet(ma,mb,R)-ans-h;
            mxh=(mxH-ans-h);
            Init(2,h,r,R,ans+h);           
        }
        if(flg==3) {
            ans+=Connet(la,lb,r)-ans;
            if(h+ans>=mxh) {
                Init(3,h,r,R,ans+h);
            } else {
                mxh=(mxH-ans-h);
                Init(2,h,r,R,ans+h);
            }
        }
        if(flg==4) {
            ans+=Connet(la,lb,r)-ans-h;
            if(h+ans>=mxh) {
                Init(3,h,r,R,ans+h);
            } else {
                mxh=(mxH-ans-h);
                Init(2,h,r,R,ans+h);
            }
        }